package com.example.elm.Account

import android.content.Intent
import android.graphics.Color
import android.os.Bundle
import android.widget.Toast
import androidx.activity.ComponentActivity
import androidx.core.view.isGone
import com.example.elm.Public.AccountInfo
import com.example.elm.databinding.EatBeanBinding

class EatbeanActivity : ComponentActivity() {
    private lateinit var binding: EatBeanBinding
    private var AccountInformation: AccountInfo? = null
    private var eat_bean = 2450
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = EatBeanBinding.inflate(layoutInflater)
        setContentView(binding.root)
        AccountInformation = CommonUtil.getSerializable(this, "info", AccountInfo::class.java)

        binding.categoryDaily.setOnClickListener{
            binding.daily.isGone = false
            binding.eat.isGone = true
            binding.drink.isGone = true
            binding.categoryDaily.setTextColor(Color.rgb(255, 111, 97))
            binding.categoryFood.setTextColor(Color.rgb(255, 255, 255))
            binding.categoryDrinks.setTextColor(Color.rgb(255, 255, 255))
        }

        binding.categoryFood.setOnClickListener{
            binding.daily.isGone = true
            binding.eat.isGone = false
            binding.drink.isGone = true
            binding.categoryDaily.setTextColor(Color.rgb(255, 255, 255))
            binding.categoryFood.setTextColor(Color.rgb(255, 111, 97))
            binding.categoryDrinks.setTextColor(Color.rgb(255, 255, 255))
        }

        binding.categoryDrinks.setOnClickListener{
            binding.daily.isGone = true
            binding.eat.isGone = true
            binding.drink.isGone = false
            binding.categoryDaily.setTextColor(Color.rgb(255, 255, 255))
            binding.categoryFood.setTextColor(Color.rgb(255, 255, 255))
            binding.categoryDrinks.setTextColor(Color.rgb(255, 111, 97))
        }

        binding.back.setOnClickListener {
            val intent = Intent()
            intent.putExtra("info", AccountInformation)
            setResult(RESULT_OK, intent)
            finish()
        }
        binding.use1Button.setOnClickListener {
            val goods = Integer.parseInt(binding.paper.getText().toString())
            if (eat_bean > goods){
                Toast.makeText(this, "兑换成功", Toast.LENGTH_SHORT).show()
                eat_bean = eat_bean - goods
                binding.mybean.text = "我的吃货豆: $eat_bean"
            }
            else
                Toast.makeText(this, "吃货豆不够", Toast.LENGTH_SHORT).show()
        }
        binding.use2Button.setOnClickListener {
            val goods = Integer.parseInt(binding.xijiejing.getText().toString())
            if (eat_bean > goods){
                Toast.makeText(this, "兑换成功", Toast.LENGTH_SHORT).show()
                eat_bean = eat_bean - goods
                binding.mybean.text = "我的吃货豆: $eat_bean"
            }
            else
                Toast.makeText(this, "吃货豆不够", Toast.LENGTH_SHORT).show()
        }
        binding.use3Button.setOnClickListener {
            val goods = Integer.parseInt(binding.warm.getText().toString())
            if (eat_bean > goods){
                Toast.makeText(this, "兑换成功", Toast.LENGTH_SHORT).show()
                eat_bean = eat_bean - goods
                binding.mybean.text = "我的吃货豆: $eat_bean"
            }
            else
                Toast.makeText(this, "吃货豆不够", Toast.LENGTH_SHORT).show()
        }
        binding.use4Button.setOnClickListener {
            val goods = Integer.parseInt(binding.mouse.getText().toString())
            if (eat_bean > goods){
                Toast.makeText(this, "兑换成功", Toast.LENGTH_SHORT).show()
                eat_bean = eat_bean - goods
                binding.mybean.text = "我的吃货豆: $eat_bean"
            }
            else
                Toast.makeText(this, "吃货豆不够", Toast.LENGTH_SHORT).show()
        }
        binding.use5Button.setOnClickListener {
            val goods = Integer.parseInt(binding.cat.getText().toString())
            if (eat_bean > goods){
                Toast.makeText(this, "兑换成功", Toast.LENGTH_SHORT).show()
                eat_bean = eat_bean - goods
                binding.mybean.text = "我的吃货豆: $eat_bean"
            }
            else
                Toast.makeText(this, "吃货豆不够", Toast.LENGTH_SHORT).show()
        }
        binding.use6Button.setOnClickListener {
            val goods = Integer.parseInt(binding.egg.getText().toString())
            if (eat_bean > goods){
                Toast.makeText(this, "兑换成功", Toast.LENGTH_SHORT).show()
                eat_bean = eat_bean - goods
                binding.mybean.text = "我的吃货豆: $eat_bean"
            }
            else
                Toast.makeText(this, "吃货豆不够", Toast.LENGTH_SHORT).show()
        }
        binding.use7Button.setOnClickListener {
            val goods = Integer.parseInt(binding.breakfirst.getText().toString())
            if (eat_bean > goods){
                Toast.makeText(this, "兑换成功", Toast.LENGTH_SHORT).show()
                eat_bean = eat_bean - goods
                binding.mybean.text = "我的吃货豆: $eat_bean"
            }
            else
                Toast.makeText(this, "吃货豆不够", Toast.LENGTH_SHORT).show()
        }
        binding.use8Button.setOnClickListener {
            val goods = Integer.parseInt(binding.oil.getText().toString())
            if (eat_bean > goods){
                Toast.makeText(this, "兑换成功", Toast.LENGTH_SHORT).show()
                eat_bean = eat_bean - goods
                binding.mybean.text = "我的吃货豆: $eat_bean"
            }
            else
                Toast.makeText(this, "吃货豆不够", Toast.LENGTH_SHORT).show()
        }
        binding.use9Button.setOnClickListener {
            val goods = Integer.parseInt(binding.maipian.getText().toString())
            if (eat_bean > goods){
                Toast.makeText(this, "兑换成功", Toast.LENGTH_SHORT).show()
                eat_bean = eat_bean - goods
                binding.mybean.text = "我的吃货豆: $eat_bean"
            }
            else
                Toast.makeText(this, "吃货豆不够", Toast.LENGTH_SHORT).show()
        }
        binding.use10Button.setOnClickListener {
            val goods = Integer.parseInt(binding.coffee.getText().toString())
            if (eat_bean > goods){
                Toast.makeText(this, "兑换成功", Toast.LENGTH_SHORT).show()
                eat_bean = eat_bean - goods
                binding.mybean.text = "我的吃货豆: $eat_bean"
            }
            else
                Toast.makeText(this, "吃货豆不够", Toast.LENGTH_SHORT).show()
        }
        binding.use11Button.setOnClickListener {
            val goods = Integer.parseInt(binding.water.getText().toString())
            if (eat_bean > goods){
                Toast.makeText(this, "兑换成功", Toast.LENGTH_SHORT).show()
                eat_bean = eat_bean - goods
                binding.mybean.text = "我的吃货豆: $eat_bean"
            }
            else
                Toast.makeText(this, "吃货豆不够", Toast.LENGTH_SHORT).show()
        }
        binding.use12Button.setOnClickListener {
            val goods = Integer.parseInt(binding.coffee2.getText().toString())
            if (eat_bean > goods){
                Toast.makeText(this, "兑换成功", Toast.LENGTH_SHORT).show()
                eat_bean = eat_bean - goods
                binding.mybean.text = "我的吃货豆: $eat_bean"
            }
            else
                Toast.makeText(this, "吃货豆不够", Toast.LENGTH_SHORT).show()
        }
    }
}